import { BaseController, CoolController } from "@cool-midway/core";
import { ProviderProviderService } from "../../service/provider";
import { Body, Inject, Post, Get, Query } from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { UpdatePartnerRelationDTO, UpdateProviderMemberDTO } from "../../dto/provider";

@CoolController({
    api: ['add'],
    service: ProviderProviderService,
})
export class ProviderController extends BaseController {
    @Inject()
    providerProviderService: ProviderProviderService;

    @Inject()
    ctx: Context


    @Post('/changeOwnerToPartner', { summary: '更改所属关系为合作关系' })
    async changeOwnerToPartner(@Body('targetProviderId') targetProviderId: number) {
        return this.ok(await this.providerProviderService.changeOwnerToPartner(targetProviderId));
    }


    @Post('/changePartnerToOwner', { summary: '更改合作关系为所属关系' })
    async changePartnerToOwner(@Body('targetProviderId') targetProviderId: number) {
        return this.ok(await this.providerProviderService.changePartnerToOwner(targetProviderId))
    }

    @Post('/deleteProviderRelation', { summary: '删除合作关系与所属关系' })
    async deleteProviderRelation(@Body('targetProviderId') targetProviderId: number) {
        return this.ok(await this.providerProviderService.deleteProviderRelation(targetProviderId));
    }

    @Get('/getTeamMembers', { summary: '获取当前团队下的所有合作成员及所属成员' })
    async getTeamMembers() {
        return this.ok(await this.providerProviderService.getTeamMembers(this.ctx.team?.id));
    }

    @Get('/getTeamMemberDetail', { summary: '查询团队成员详情' })
    async getTeamMemberDetail(@Query('providerId') providerId: number) {
        return this.ok(await this.providerProviderService.getTeamMemberDetail(providerId, this.ctx.team?.id));
    }

    @Post('/updateMemberProfile', { summary: '编辑团队成员档案' })
    async updateMemberProfile(@Body() body: UpdateProviderMemberDTO) {
        return this.ok(await this.providerProviderService.updateMemberProfile(body));
    }

    @Post('/updatePartnerRelation', { summary: '编辑合作关系' })
    async updatePartnerRelation(@Body() body: UpdatePartnerRelationDTO) {
        return this.ok(await this.providerProviderService.updatePartnerRelation(body));
    }

}